/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.agi.devsol.aplicacao.estimativa;

import br.com.agi.devsol.dominio.Estimativa;
import br.com.agi.devsol.ejb.estimativa.ListadorEstimativa;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author rgrosz
 */
@ConversationScoped
@Named
public class ListagemEstimativa implements Serializable{
    
    
    private List <EstimativaWebAction> estimativas;
    
    @Inject
    private Conversation conversation;
    
    @EJB
    private ListadorEstimativa listadorEstimativa;
    
    public void initConversation(){
        if(!conversation.isTransient()){
            conversation.end();
        }
        conversation.begin();
    }
    
    public void setConversation(Conversation conversation){
        this.conversation = conversation;
    }
    
    
    
    public void createLista(){
        List<Estimativa> listaEstimativa = this.listadorEstimativa.getEstimativas();
        this.estimativas = new ArrayList<EstimativaWebAction>();
        for(Estimativa item : listaEstimativa){
            EstimativaWebAction wAction = new EstimativaWebAction(item);
            this.estimativas.add(wAction);
        }
    }
    
    public List<EstimativaWebAction> getEstimativas(){
        return this.estimativas;
    }

    public void setListadorEstimativa(ListadorEstimativa listadorEstimativa){
        this.listadorEstimativa = listadorEstimativa;
    }
    

}
